using System.Collections.Generic;


namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_SetValueInList_RT : RT_Node
    {
        public RT_ValueListPort ValueList_RT;

        public RT_SingleValuePort Index_RT;

        public RT_SingleValuePort NewValue_RT;

        public RT_ValueListPort ResultList_RT;

        public Node_SetValueInList_RT(Node_SetValueInList sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            ValueList_RT = new RT_ValueListPort(EPortIOType.Input, sourceData.ValueList, this);

            Index_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Index, this);

            NewValue_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.NewValue, this);

            ResultList_RT = new RT_ValueListPort(EPortIOType.Output, sourceData.ResultList, this);
            ResultList_RT.OnGetValueList = GetResultList;
        }

        public List<AValue> GetResultList(DAG_Executor executor)
        {
            var vList = ValueList_RT.GetValueList(executor);
            int index = Index_RT.GetValue(executor).ToInteger().Item2;
            var newV = NewValue_RT.GetValue(executor);

            if (index >= 0 && index < vList.Count)
            {
                vList[index].Assign(newV);
            }
            return vList;
        }
    }
}